var req;

/******
Marque
******/

function selectMarque(marque) {
	if (marque > 0 || marque == -1) {
		var url = '/accessoires/ajax.do?marque=' + marque;
		
		req = null;
		
		var select = document.getElementById('mobile_id');
		select.options.length = 0;
		
		if (marque == -1) {
			select.options[0] = new Option("Selectionner votre mobile", -1);
		}
		
		req = sendAjaxGetRequest(url, selectMarqueProcess);
	}
}

function selectMarqueProcess() {
	if (req == null) {
		return;
	}
	
	if (req.readyState == 4) {
		if (req.status == 200) {
			var select = document.getElementById('mobile_id');
			var root = req.responseXML.documentElement;
			var mobiles = root.getElementsByTagName('mobile');

			var initialLength = select.length;

			for (i=0 ; i<mobiles.length ; i++) {
				var mobile = mobiles.item(i).childNodes;
				var id;
				var name;
				
				for (j=0 ; j<mobile.length ; j++) {
					var node = mobile[j];
					
					if (node.nodeName == "id") {
						id = node.childNodes[0].nodeValue;
					} else if (node.nodeName == "name_without_color") {
						name = node.childNodes[0].nodeValue;
					}
				}
				
				select.options[i+initialLength] = new Option(name, id);
			}
		}
	}
}

/***
Process
***/

function gogo()
{
	el = document.getElementById('mobile_id');
	el2 = document.getElementById('category_id');
	if( el2 != null )
	{ 
		window.location='/accessoires/search.do?mobsorted='+el.value+'&category='+el2.value;
	}
	else
	{
		window.location='/accessoires/search.do?mobsorted='+el.value;
	}        
}
